// pages/boxState/boxState.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      isOpening: options.isOpening,
      _box_bn: options.box_bn,
      _box_id: options.box_id
    })
    wx.setNavigationBarTitle({
      title: '开箱中',
    })

    var that = this;
    var _box_bn = options.box_bn;

  },

  // 判断箱子是否开启状态  
  getBoxState: function (_box_bn) {
    var that = this;
    wx.request({
      url: "https://boxapi.supergk.com/server/box/query_box_lid_status",
      header: {
        "content-type": "application/x-www-form-urlencoded"
      },
      method: "POST",
      data: util.json2Form({
        box_bn: _box_bn
      }),
      success: function (result) {
        console.log(result)
        if (result.data.code == 0) {
          console.log("操作成功");
          console.log(result.data.msg);

          if (result.data.data.lid_state == "close") {
            console.log("开箱中……")
            console.log("关箱成功")
            that.setData({
              isOpening: 1,
              isCloseding: 0
            });
          } else if (result.data.data.lid_state == "open") {
            console.log("开箱成功")
            console.log("关箱中……")
            that.setData({
              isOpening: 0,
              isCloseding: 1
            });
          }
          //成功提示
          wx.showToast({
            title: result.data.msg,
            icon: "success"
          })
        } else {
          console.log(result.data.msg)
          wx.showModal({
            title: '提示',
            content: result.data.msg,
            showCancel: false
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})